package com.kadron.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.validator.NotNull;

import com.kadron.base.KTBase;

@Entity
@Table(name = "k_item")
public class Item extends KTBase implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1990450313599525624L;

	private Application application;
	private ItemType itemType;
	private boolean active;
	private Date validFrom;
	private Date validTo;
	
	private long kadrons;
	
	public Item() {
		super();
	}

	public Item(Application application, ItemType itemType) {
		super();
		this.application = application;
		this.itemType = itemType;
	}

	@NotNull
	@ManyToOne(targetEntity = Application.class)
	@JoinColumn(name = "a_id")
	public Application getApplication() {
		return application;
	}

	public void setApplication(Application application) {
		this.application = application;
	}

	@NotNull
	@ManyToOne(targetEntity = ItemType.class)
	@JoinColumn(name = "it_id")
	public ItemType getItemType() {
		return itemType;
	}

	public void setItemType(ItemType itemType) {
		this.itemType = itemType;
	}

	@Column(name = "active")
	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}
	
	@Temporal(TemporalType.DATE)
	@Column(name = "valid_from")
	public Date getValidFrom() {
		return validFrom;
	}

	public void setValidFrom(Date validFrom) {
		this.validFrom = validFrom;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "valid_to")
	public Date getValidTo() {
		return validTo;
	}

	public void setValidTo(Date validTo) {
		this.validTo = validTo;
	}

	@Column(name = "kadrons")
	public long getKadrons() {
		return kadrons;
	}

	public void setKadrons(long kadrons) {
		this.kadrons = kadrons;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Item other = (Item) obj;
		if (id != other.id)
			return false;
		return true;
	}
	
}
